package com.wanglei.distributed

import java.io.ObjectInputStream
import java.net.ServerSocket

object Executor1 {

  def main(args: Array[String]): Unit = {
    // 启动服务接收Driver数据
    val server = new ServerSocket(9000)
    println("executor1等待driver分发任务")

    // 等待Driver的连接
    val socket = server.accept()

    // 接收消息
    val stream = socket.getInputStream
    val objStream = new ObjectInputStream(stream)
    val task = objStream.readObject().asInstanceOf[SubTask]
    val result = task.compute()
    println("executor1收到了driver的数据" + task)
    println("executor1计算的结果为" + result)



    // 关闭资源
    stream.close()
    socket.close()
    server.close()
  }
}
